package com.loe.mvp

import android.app.Application
import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import com.loe.mvp.ext_java.AsyncTimer
import com.loe.mvp.ext_java.timer

abstract class BaseInitProvider : ContentProvider()
{
    lateinit var app: Application

    override fun onCreate(): Boolean
    {
        onAppCreateBefore()
        var timerTask: AsyncTimer? = null
        timerTask = timer(100, 100, 100)
        {
            if(timerTask != null && context?.applicationContext != null)
            {
                timerTask?.stop()
                timerTask = null
                app = context?.applicationContext as Application
                onAppCreateAfter(app)
            }
        }
        return true
    }

    /** application.onCreate()之前调用 */
    abstract fun onAppCreateBefore()

    /** application.onCreate()之后调用 */
    abstract fun onAppCreateAfter(app: Application)

    override fun query(uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?, sortOrder: String?): Cursor?
    {
        return null
    }

    override fun getType(uri: Uri): String?
    {
        return null
    }

    override fun insert(uri: Uri, values: ContentValues?): Uri?
    {
        return null
    }

    override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int
    {
        return 0
    }

    override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?): Int
    {
        return 0
    }
}